package cn.itcast.user.controller;

import cn.itcast.hmall.pojo.user.User;
import cn.itcast.user.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class UserController {
    @Autowired
    IUserService userService;

    /**
     * 根据用户id 获取用户信息
     * @param id
     * @return
     */
    @GetMapping("/user/{id}")
    public User getUser(@PathVariable("id")Long id){
        return userService.getById(id);
    }

    /**
     * 扣减用户余额接口
     * @param money
     * @param id
     */
    @RequestMapping("/user/pay/{money}/{id}")
    public void pay(@PathVariable("money")Long money, @PathVariable("id")Long id){
        log.info("扣减用户余额:-{}",money);
        userService.pay(money,id);
    }
}
